<template>
	<view>
		<!-- 一.未实名认证，显示实名提示 -->
		<view class="review-container" v-show="!realAuthSuccess">
			<image src="/static/workbench/review2.png" mode="widthFix"></image>
			<view class="title">{{ title }}</view>
			<view class="desc">这期间您将无法接单，请实名认证后进行接单</view>
			<view class="toRealAuth">
				<button class="btn" @click="toRealAuth">我要认证</button>
			</view>
		</view>
		<!-- 二.实名成功，显示司机的统计数据 -->
		<view v-show="realAuthSuccess">
			<view class="top-container">
				<view class="notice">今日数据：凌晨00:00 ~ 本日23:59</view>
				<view class="summary-container">
					<view class="item">
						<view class="title">代驾时长</view>
						<view class="value">
							<text class="number">{{ summary.driveDuration }}</text>
							<text class="unit">时</text>
						</view>
					</view>
					<view class="item">
						<view class="title">今日收入</view>
						<view class="value">
							<text class="number">{{ summary.todayIncome }}</text>
							<text class="unit">元</text>
						</view>
					</view>
					<view class="item">
						<view class="title">今日成单</view>
						<view class="value">
							<text class="number">{{ summary.todayTradeOrders }}</text>
							<text class="unit">单</text>
						</view>
					</view>
				</view>
				<view class="service-container">
					<view class="item" :style="service.locationStyle">
						<image :src="service.locationIcon" mode="widthFix" class="icon icon-1"></image>
						{{ service.locationText }}
					</view>
					<view class="item" :style="service.messageStyle">
						<image :src="service.messageIcon" mode="widthFix" class="icon icon-2"></image>
						{{ service.messageText }}
					</view>
					<view class="item" :style="service.listenStyle" @tap="listenHandle()">
						<image :src="service.listenIcon" mode="widthFix" class="icon icon-3"></image>
						{{ service.listenText }}
					</view>
					<view class="item" :style="service.settingStyle" @tap="settingHandle()">
						<image :src="service.settingIcon" mode="widthFix" class="icon icon-4"></image>
						{{ service.settingText }}
					</view>
				</view>
			</view>
			<!-- 三.停止接单 -->
			<view v-show="workStatus == '停止接单'">
				<map id="map" :longitude="location.longitude" :latitude="location.latitude" scale="15"
					:style="contentStyle" :enable-traffic="true" :show-location="true" :enable-poi="true"
					style="width: 100%;">
					<cover-image class="location" src="../../static/workbench/location.png"
						@tap="returnLocationHandle()"></cover-image>
				</map>
			</view>
			<!-- 四.显示开始接单 -->
			<scroll-view scroll-y="true" :style="contentStyle" v-show="workStatus == '开始接单'">
				<view class="new-order">
					<view v-if="newOrder == null">
						<image src="../../static/workbench/no-order.png" mode="widthFix" class="no-order-img"></image>
						<view class="no-order-title">目前暂无订单</view>
					</view>

					<!-- 五.拉取到订单，执行抢单 -->
					<view v-if="newOrder != null">
						<view class="line-1">
							<view>
								<view class="sub-time">距离您</view>
								<view>
									<text class="number">{{ newOrder.distance }}</text>
									<text class="unit">公里</text>
								</view>
							</view>
							<view>
								<view class="sub-time">全程</view>
								<view>
									<text class="number">{{ newOrder.mileage }}</text>
									<text class="unit">公里</text>
								</view>
							</view>
							<view>
								<view class="tag">预估</view>
								<view>
									<text class="number">{{ newOrder.orderAmount }}</text>
									<text class="unit">元</text>
								</view>
							</view>
						</view>
						<view class="line-2">
							<view class="from">
								<text>{{ newOrder.startPlace }}</text>
							</view>
							<view class="dashed-line"></view>
							<view class="to">
								<text>{{ newOrder.endPlace }}</text>
							</view>
						</view>
						<button class="accept-btn" @tap="killOrderHandle">立即抢单</button>
						<button class="disabled-btn" @tap="ignoreHandle">拒绝接单</button>

					</view>
				</view>
				<view class="notice-container">
					<view class="title">【 抢单说明 】</view>
					<view class="desc">
						<text class="num">1.</text>
						当前地区可能存在多个代驾订单，但是司机端只能显示其中一条订单。这是为了保障代驾乘客订单的接单率，避免代驾司机只挑选优质订单。
					</view>
					<view class="desc">
						<text class="num">2.</text>
						某条订单如果10秒钟之内您没有抢单，系统则认定您主动放弃该订单，系统将为你推送新的订单。
					</view>
				</view>
			</scroll-view>
			<!-- 六.抢到订单，显示订单详情 -->
			<scroll-view scroll-y="true" :style="contentStyle" class="execute-order-container"
				v-show="['接客户', '到达代驾点', '开始代驾'].includes(workStatus)">
				<view class="call" @tap="callCustomerHandle"></view>
				<view class="customer-container">
					<u-avatar :src="executeOrder.customerPhoto" mode="square"></u-avatar>
					<view class="info">
						<view class="customer-name">代驾客户（{{ executeOrder.customerName }}）</view>
						<view class="customer-phone">phone：{{ executeOrder.customerPhone }}</view>
					</view>
				</view>
				<view class="address-container">
					<view class="from">
						<text>{{ executeOrder.startPlace }}</text>
					</view>
					<view class="dashed-line"></view>
					<view class="to">
						<text>{{ executeOrder.endPlace }}</text>
					</view>
				</view>
				<view class="order-container">
					<view style="font-size: 13px;">【 订单号码 】 {{ executeOrder.orderNo }}</view>
					<view>【 下单时间 】 {{ executeOrder.createTime }}</view>
					<view>【 客户红包 】 {{ executeOrder.favourAmount }}元</view>
					<view>【 代驾车型 】 {{ executeOrder.carType }}</view>
					<view>【 代驾车牌 】 {{ executeOrder.carPlate }}</view>
				</view>
				<view class="operate-container">
					<view class="item">
						<image src="../../static/workbench/alarm-icon2.png" mode="widthFix" class="alarm-icon"></image>
						<text class="alarm-text">立即报警</text>
					</view>

					<view class="vline"></view>
					<view class="item" v-show="workStatus == '接客户'" @tap="arriveStartPlaceHandle">
						<image src="../../static/workbench/arrive-start-icon.png" mode="widthFix"
							class="arrive-start-icon"></image>
						<text class="arrive-start-text">到达代驾点</text>
					</view>
					<view class="item" v-show="workStatus == '到达代驾点'" @tap="startDrivingHandle">
						<image src="../../static/workbench/drive-start-icon.png" mode="widthFix"
							class="drive-start-icon"></image>
						<text class="drive-start-text">开始代驾</text>
					</view>
					<!-- <button class="item btn" v-show="workStatus == '开始代驾'"  open-type="getPhoneNumber" @getphonenumber="endDrivingHandle">-->

					<view class="item" v-show="workStatus == '开始代驾'" @tap="endDrivingHandle">
						<image src="../../static/workbench/drive-stop-icon.png" mode="widthFix" class="drive-stop-icon">
						</image>
						<text class="drive-stop-text">结束代驾</text>
					</view>
					<view class="vline"></view>
					<view class="item" @tap="cancelOrderHandle">
						<image src="../../static/workbench/cancel-icon.png" mode="widthFix" class="cancel-icon"></image>
						<text class="cancel-text">取消订单</text>
					</view>
				</view>
				<view class="other-container">
					<view class="item" @tap="showNavigationHandle">
						<image src="../../static/workbench/other-icon-a.png" mode="widthFix" class="location-icon">
						</image>
						<text class="location-text">定位导航</text>
					</view>
					<view class="item" @tap="showMoveHandle">
						<image src="../../static/workbench/other-icon-b.png" mode="widthFix" class="display-icon">
						</image>
						<text class="display-text">司乘同显</text>
					</view>
					<view class="item" @tap="showOrderHandle">
						<image src="../../static/workbench/other-icon-c.png" mode="widthFix" class="order-icon"></image>
						<text class="order-text">订单详情</text>
					</view>
					<view class="item" @tap="callServiceHandle">
						<image src="../../static/workbench/other-icon-d.png" mode="widthFix" class="service-icon">
						</image>
						<text class="service-text">客服热线</text>
					</view>
				</view>
			</scroll-view>

			<!-- 七.开始接单和停止接单 -->
			<view class="bottom-container" v-show="['开始接单', '停止接单'].includes(workStatus)">
				<view class="btn" @tap="gohomeHandle()">
					<image src="../../static/workbench/btn-icon-1.png" mode="widthFix" class="btn-icon-1"></image>
					<text>回家</text>
				</view>
				<view class="btn primary">
					<text v-show="workStatus == '停止接单'" @tap="startWorkHandle()">开始接单</text>
					<text v-show="workStatus == '开始接单'" @tap="stopWorkHandle()">停止接单</text>
				</view>
				<view class="btn" @tap="rechargeHandle()">
					<image src="../../static/workbench/btn-icon-2.png" mode="widthFix" class="btn-icon-2"></image>
					<text>充值</text>
				</view>
			</view>
		</view>
		<u-top-tips ref="uTips"></u-top-tips>
		<u-toast ref="uToast" />
		<u-modal v-model="model.cancelConfirm.show" :title="model.cancelConfirm.title"
			:content="model.cancelConfirm.content" :show-confirm-button="true" :show-cancel-button="true"
			@confirm="confirmCancelOrder"></u-modal>
		<u-modal v-model="model.cancelSuccess.show" :title="model.cancelSuccess.title"
			:content="model.cancelSuccess.content" :show-confirm-button="true" :show-cancel-button="false"></u-modal>
	</view>
</template>

<script>
	import GtPush from '../../lib/gtpush-min.js'
	//腾讯地图插件
	let QQMapWX = require('../../lib/qqmap-wx-jssdk.min.js');
	let qqmapsdk;

	//录音
	let wechatSIPlugin = requirePlugin('WechatSI');
	let dayjs = require('dayjs');

	export default {
		data() {
			return {
				//屏幕窗口高度
				windowHeight: 0,
				contentStyle: '',
				//地图控件
				_mapContext: null,
				//语音播放器
				voicePlayer: null,
				//标题默认值
				title: "请进行实名认证",
				//是否实名认证成功
				realAuthSuccess: false,
				//个推初始化
				getui: {
					appid: '7i5yGYbYBG7q275zJ7Cqh5',
					cid: '',
					online: false,
					messages: '',
				},
				//服务图标和文本
				service: {
					locationIcon: '../../static/workbench/service-icon-1.png',
					locationText: '定位正常',
					locationStyle: '',
					messageIcon: '../../static/workbench/service-icon-2.png',
					messageText: '推送正常',
					messageStyle: '',
					listenIcon: '../../static/workbench/service-icon-3.png',
					listenText: '收听订单',
					listenStyle: '',
					settingIcon: '../../static/workbench/service-icon-4.png',
					settingText: '接单设置',
					settingStyle: ''
				},
				//司机的今日结算数据
				summary: {
					//驾龄
					driveDuration: 0,
					//今日收入
					todayIncome: 0,
					//订单数量
					todayTradeOrders: 0,
				},
				//司机的设置
				settings: {
					listenService: true,
					autoAccept: false
				},
				//司机当前定位，用户展示地图中心位子
				location: {
					latitude: "",
					longitude: "",
				},
				//司机当前的工作状态
				workStatus: uni.getStorageSync('workStatus') || "停止接单",
				//轮询获取订单的定时器
				pullOrderTimer: null,
				//新订单，当前展示
				newOrder: null,
				//订单列表，所有订单
				newOrderList: [],
				//当前执行中的订单
				accpeting: false,
				executeOrder: {
					orderNo: '',
					customerId: '',
					customerPhoto: '',
					customerName: '',
					customerPhone: '',
					carType: '',
					carPlate: '',
					startPlace: '',
					startLongitude: '',
					startLatitude: '',
					endPlace: '',
					endLongitude: '',
					endLatitude: '',
					favourAmount: '',
					acceptTime: ''
				},
				//显示弹窗
				showModel: false,
				modelTitle: '',
				modelContent: '',
				model: {
					cancelConfirm: {
						show: false,
						title: '提示消息',
						content: '如果不满足订单免费取消规则，只能有偿取消订单，并且可能被禁止接单一段时间，您确认要取消当前订单？'
					},
					cancelSuccess: {
						show: false,
						title: '提示消息',
						content: ''
					}
				},
				//录音相关
				recordNum: 0,
				recordManager: null,
				stopRecord: false,
			};
		},

		methods: {
			//初始化
			init() {
				const _this = this;
				//处理窗口样式
				let windowHeight = uni.getSystemInfoSync().windowHeight;
				_this.windowHeight = windowHeight - 200;
				_this.contentStyle = `height:${_this.windowHeight}px;`;
				//初始化地图
				_this._mapContext = uni.createMapContext("map", _this);
				uni.getLocation({
					type: 'wgs84', // 返回可以用于uni.openLocation的经纬度，默认为wgs84的gps坐标
					success: (res) => {
						_this.location.longitude = res.longitude;
						_this.location.latitude = res.latitude;
					},
					fail: (err) => {
						console.error('获取位置失败：', err);
					}
				});
				//创建音频播放器
				_this.voicePlayer = uni.createInnerAudioContext();
			},
			//初始化个推
			initGeTui() {
				let _this = this;
				GtPush.setDebugMode(true)
				GtPush.init({
					appid: _this.getui.appid,
					onClientId: (res) => {
						_this.getui.cid = res.cid
						_this.get("/message/app/gtPush/bindAlias/" + _this.getui.cid, (res) => {
							if (res.success) {
								console.log("---初始化个推成功---")
							} else {
								uni.showToast({
									title: res.message,
									icon: "error"
								})
								return;
							}
						})
					},
					onlineState: (res) => {
						_this.getui.online = res.online
					},
					onPushMsg: (res) => {
						console.log("---收到个推消息---")
						console.log(res)
						messageObj = JSON.parse(res.message);
						// 提取信息
						const orderNo = messageObj.orderNo; // 订单号
						const type = messageObj.type; // 消息类型
						if (type == 0 && orderNo == this.executeOrder.orderNo) {
							//乘客取消订单--重新获取当前司机工作状态
							console.log("---乘客取消订单---")
							uni.showToast({
								title: "乘客取消订单",
								icon: "error",
							})
							_this.getDriverWorkStatus();
						}
					},
					onError: (res) => {
						_this.getui.messages += "onError: " + res.error + "\n"
					}
				})
			},
			//----------业务方法----------
			//重定位到当前位置
			returnLocationHandle() {
				const _this = this;
				_this._mapContext.moveToLocation();
			},
			//司机上线
			startWorkHandle() {
				//1.发送请求给后端表示上线
				const _this = this;
				_this.get("/driver/app/driver/online", (res) => {
					if (res.success) {
						console.log("---上线成功---")
						//1.修改workStatus状态
						uni.setStorageSync("workStatus", _this.Constants.WORK_STATUS.START_ACCPET_ORDER);
						_this.workStatus = _this.Constants.WORK_STATUS.START_ACCPET_ORDER;
						//3.播放语音
						_this.playAudio("/static/voice/voice_1.mp3");
						//4.主动拉单
						_this.pullOrder();
						//5.开启定时器主动拉单
						_this.setInterval();
						//2.通过事件总线调用app页面的方法将位置信息上传到GEO
						uni.$emit('uploadDriverLocation2Geo', _this.location.longitude, _this.location.latitude);
					} else {
						uni.showToast({
							title: res.message,
							icon: "error"
						})
						return;
					}
				})
			},
			//司机下线
			stopWorkHandle() {
				//1.发送请求给后端表示下线
				const _this = this;
				_this.get("/driver/app/driver/offline", (res) => {
					if (res.success) {
						console.log("---下线成功---");
						//2.修改workStatus状态
						uni.setStorageSync("workStatus", _this.Constants.WORK_STATUS.STOP_ACCPET_ORDER);
						_this.workStatus = _this.Constants.WORK_STATUS.STOP_ACCPET_ORDER;
						//3.播放语音
						_this.playAudio("/static/voice/voice_2.mp3");
						//4.关闭定时器
						console.log("关闭定时器")
						clearInterval(_this.pullOrderTimer);
						_this.pullOrderTimer = null;  // 手动将定时器设置为 null
					}else{
						uni.showToast({
							title: res.message,
							icon: "error"
						})
					}
				})
			},
			//定时去拉取订单
			pullOrder() {
				const _this = this;
				_this.get("/order/app/order/driver/pullOrder", (res) => {
					const data = res.data;
					if (res.success && data && data.length > 0) {
						_this.newOrderList = data;
						_this.newOrder = _this.newOrderList[0];
						_this.remindOrder(_this.newOrder.remindOrder);
					}
				})
			},
			//秒杀订单
			killOrderHandle() {
				const _this = this;
				_this.get("/order/app/order/driver/killOrder/" + _this.newOrder.orderNo, (res) => {
					const data = res.data;
					if (res.success) {
						console.log("---抢单成功---")
						_this.executeOrder = data;
						uni.setStorageSync("workStatus", _this.Constants.WORK_STATUS.RECEPTION_CUSTOMER);
						_this.workStatus = _this.Constants.WORK_STATUS.RECEPTION_CUSTOMER;
						uni.setStorageSync("orderNo", _this.executeOrder.orderNo);
					} else {
						console.log("---抢单失败")
						_this.ignoreHandle();
					}
				})
			},
			//拒绝接单
			ignoreHandle() {
				const _this = this;
				if (_this.newOrderList && _this.newOrderList.length > 1) {
					console.log("拒绝成功")
					_this.newOrderList.shift();
					_this.newOrder = _this.newOrderList[0];
				} else {
					console.log("订单清空")
					_this.newOrder = null;
					_this.newOrderList = [];
					_this.pullOrder();
				}
			},
			//司机取消订单
			cancelOrderHandle() {
				const _this = this;
				const param = {
					sendId: _this.executeOrder.customerId,
					orderNo: _this.executeOrder.orderNo
				}
				_this.post("/message/app/gtPush/driver/cancelOrder", param, (res) => {
					if (res.success) {
						console.log("---取消订单成功---");
						_this.getDriverAuthInfo();
					} else {
						console.log("---取消订单失败---")
					}
				})
			},
			//----------维护页面方法----------
			// 获取司机实名认证信息
			getDriverAuthInfo() {
				const _this = this;
				_this.get("/driver/app/auth/authInfo", (res) => {
					const data = res.data;
					if (res.success) {
						if (data && data.realAuthStatus) {
							console.log("---获取司机实名认证信息成功---");
							if (data.realAuthStatus == 1) {
								_this.realAuthSuccess = true;
								// 仅在实名认证成功时获取司机今日统计数据和当前状态
								_this.getDriverSummaryTodayInfo();
								_this.getDriverWorkStatus();
							} else {
								if (data.realAuthStatus == 0) {
									_this.title = "审核中,请等待审核通过"
								} else if (data.realAuthStatus == 2) {
									_this.title = "审核失败,失败原因为" + data.auditRemark
								} else if (data.realAuthStatus == 3) {
									_this.title = "认证撤销,撤销原因为" + data.auditRemark
								}
								uni.setStorageSync("driverAuthMaterial", data);
							}
						}
					} else {
						uni.showToast({
							title: "获取数据失败",
							icon: "error"
						})
					}
				})
			},
			// 获取司机今日接单数据
			getDriverSummaryTodayInfo() {
				const _this = this;
				_this.get("/driver/app/summary", (res) => {
					const data = res.data;
					if (res.success) {
						console.log("---获取司机今日接单数据成功---");
						// 使用 Object.assign 将 data 的所有属性赋值给 _this.summary
						Object.assign(_this.summary, data);
					} else {
						uni.showToast({
							title: "获取数据失败",
							icon: "error"
						})
					}
				})
			},
			// 获取司机状态
			getDriverWorkStatus() {
				const _this = this;
				_this.get('/order/app/order/driver/workStatus', (res) => {
					const data = res.data;
					if (res.success) {
						console.log("---获取司机上线状态成功---");
						_this.executeOrder = data;
						if (data) {
							if (data.status == _this.Constants.OrderStatus.ORDER_STATUS_WAIT) {
								console.log("---司机处于上线状态---");
								uni.setStorageSync("workStatus", _this.Constants.WORK_STATUS.START_ACCPET_ORDER);
								_this.workStatus = _this.Constants.WORK_STATUS.START_ACCPET_ORDER;
								_this.pullOrder();
								_this.setInterval();
							} else if (data.status == _this.Constants.OrderStatus.ORDER_STATUS_ACCEPTED) {
								console.log("---司机处于接客户状态---");
								uni.setStorageSync("workStatus", _this.Constants.WORK_STATUS.RECEPTION_CUSTOMER);
								_this.workStatus = _this.Constants.WORK_STATUS.RECEPTION_CUSTOMER;
								uni.setStorageSync("orderNo", _this.executeOrder.orderNo);
							} else if (data.status == _this.Constants.OrderStatus.ORDER_STATUS_ARRIVE) {
								console.log("---司机处于到达代驾点状态---");
								uni.setStorageSync("workStatus", _this.Constants.WORK_STATUS.ARRIVE_START_PLACE);
								_this.workStatus = _this.Constants.WORK_STATUS.ARRIVE_START_PLACE;
								uni.setStorageSync("orderNo", _this.executeOrder.orderNo);
							} else if (data.status == _this.Constants.OrderStatus.ORDER_STATUS_START_DRIVING) {
								console.log("---司机处于开始代驾状态---");
								uni.setStorageSync("workStatus", _this.Constants.WORK_STATUS.START_DRIVING);
								_this.workStatus = _this.Constants.WORK_STATUS.START_DRIVING;
								uni.setStorageSync("orderNo", _this.executeOrder.orderNo);
							} else if (data.status == _this.Constants.OrderStatus.ORDER_STATUS_COMPLETE_DRIVED) {
								console.log("---司机处于结束代驾状态---");
								uni.setStorageSync("workStatus", _this.Constants.WORK_STATUS.END_DRIVING);
								_this.workStatus = _this.Constants.WORK_STATUS.END_DRIVING;
								uni.setStorageSync("orderNo", _this.executeOrder.orderNo);
								_this.showEnterFeeHandle();
							}
						} else {
							console.log("---司机处于下线状态---")
							uni.setStorageSync("workStatus", _this.Constants.WORK_STATUS.STOP_ACCPET_ORDER);
							_this.workStatus = _this.Constants.WORK_STATUS.STOP_ACCPET_ORDER;
						}
					} else {
						uni.showToast({
							title: "获取状态失败",
							icon: "error"
						})
					}
				})
			},
			//----------抽取方法----------
			//播放指定路径音频
			playAudio(src) {
				let _this = this;
				_this.voicePlayer.src = src;
				_this.voicePlayer.play();
			},
			//开启定时器
			setInterval() {
				const _this = this;
				if (_this.pullOrderTimer) {
					return;
				}
				_this.pullOrderTimer = setInterval(() => {
					console.log("定时器1执行了")
					console.log("当前司机状态为:" + _this.workStatus)
					console.log("----------")
					if (_this.workStatus == _this.Constants.WORK_STATUS.START_ACCPET_ORDER) {
						if (_this.newOrderList.length == 0) {
							_this.pullOrder();
						}
					} else {
						console.log("关闭定时器")
						clearInterval(_this.pullOrderTimer);
						_this.pullOrderTimer = null;  // 手动将定时器设置为 null
					}
				}, 5000)
			},
			//同声传译语音播报插件
			remindOrder(text) {
				const _this = this
				wechatSIPlugin.textToSpeech({
					lang: "zh_CN",
					tts: true,
					content: text,
					success: function(res) {
						console.log(text)
						console.log("---文本转换语音成功---")
						_this.playAudio(res.filename)
					},
					fail: function(res) {
						console.log("fail tts", res)
					}
				})
			},
			//司机给乘客打电话
			callCustomerHandle() {
				console.log("-----开始播打电话-----")
				uni.makePhoneCall({
					phoneNumber: '18481024368' //仅为示例
				});
			},
			callServiceHandle() {
				console.log("-----开始播打电话-----")
				uni.makePhoneCall({
					phoneNumber: '18481024368' //仅为示例
				});
			},
			//----------状态改变方法----------
			//到达代驾点
			arriveStartPlaceHandle() {
				const _this = this;
				_this.post("/order/app/order/driver/arrive/" + _this.executeOrder.orderNo, (res) => {
					if (res.success) {
						console.log("-----到达代驾点-----")
						uni.setStorageSync("workStatus", _this.Constants.WORK_STATUS.ARRIVE_START_PLACE);
						_this.workStatus = _this.Constants.WORK_STATUS.ARRIVE_START_PLACE;
					} else {
						uni.showToast({
							title: res.message,
							icon: "error"
						})
					}
				})
			},
			//开始代驾
			startDrivingHandle() {
				const _this = this;
				_this.post("/order/app/order/driver/start/" + _this.executeOrder.orderNo, (res) => {
					if (res.success) {
						console.log("-----开始代驾-----")
						uni.setStorageSync("workStatus", _this.Constants.WORK_STATUS.START_DRIVING);
						_this.workStatus = _this.Constants.WORK_STATUS.START_DRIVING;
					} else {
						uni.showToast({
							title: res.message,
							icon: "error"
						})
					}
				})
			},
			//结束代驾
			endDrivingHandle() {
				const _this = this;
				_this.post("/order/app/order/driver/end/" + _this.executeOrder.orderNo, (res) => {
					if (res.success) {
						console.log("-----结束代驾-----")
						uni.setStorageSync("workStatus", _this.Constants.WORK_STATUS.END_DRIVING);
						_this.workStatus = _this.Constants.WORK_STATUS.END_DRIVING;
						_this.showEnterFeeHandle();
					} else {
						uni.showToast({
							title: res.message,
							icon: "error"
						})
					}
				})

			},
			//----------页面跳转方法----------
			//跳转到实名认证页面
			toRealAuth() {
				uni.navigateTo({
					url: "/identity/filling/filling",
				})
			},
			//显示司乘同显界面
			showMoveHandle() {
				uni.navigateTo({
					url: "/execution/move/move?orderNo=" + this.executeOrder.orderNo
				})
			},
			//跳转到订单详情页面
			showOrderHandle() {
				uni.switchTab({
					url: "/pages/order_list/order_list"
				})
			},
			//跳转到订单确认费用页面
			showEnterFeeHandle() {
				uni.navigateTo({
					url: "/order/enter_fee/enter_fee?orderNo=" + this.executeOrder.orderNo
				})
			}
		},
		onLoad() {
			const _this = this;
			//初始化
			_this.init();
			//初始化个推
			//_this.initGeTui();
			uni.$on('resetWorkStatus', this.resetWorkStatus);
			uni.$on('arriveStartPlaceHandle', this.arriveStartPlaceHandle);
			uni.$on('endDrivingHandle', this.endDrivingHandle);
		},
		onShow() {
			const _this = this;
			//获取司机实名信息
			_this.getDriverAuthInfo();
		},
		onUnload() {
			console.log("关闭定时器")
			clearInterval(this.pullOrderTimer);
			uni.$off('resetWorkStatus', this.resetWorkStatus);
			uni.$off('arriveStartPlaceHandle', this.arriveStartPlaceHandle);
			uni.$off('endDrivingHandle', this.endDrivingHandle);
		},
	};
</script>

<style lang="less">
	@import url('workbench.less');
</style>